home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / AIAT / Headers / Analysis / IAAnalysis.h < prev    next >
Encoding:
Text File  |  1998-04-16  |  4.0 KB  |  131 lines  |  [TEXT/CWIE]

  1. // IAAnalysis.h
  2. //    Copyright:    © 1994 - 1998 by Apple Computer, Inc., all rights reserved.
  3.  
  4. #pragma once
  5. #ifndef IAAnalysis_h
  6. #define IAAnalysis_h
  7.  
  8. #pragma import on
  9. #if PRAGMA_STRUCT_ALIGN
  10.     #pragma options align=power
  11. #endif
  12.  
  13. #include "IACorpus.h"
  14.  
  15. #pragma IA_BEGIN_EXPORTS
  16.  
  17. class IATerm : public IAOrderedStorable {
  18. public:
  19.                     IATerm(const byte* d, uint32 l);
  20.     virtual            ~IATerm();                                // frees data
  21.  
  22.     IAStorable*        DeepCopy() const;
  23.     IABlockSize        StoreSize() const;
  24.     void            Store(IAOutputBlock* output) const;
  25.     IAStorable*        Restore(IAInputBlock* input) const;
  26.  
  27.     bool            LessThan(const IAOrderedStorable* neighbor) const;
  28.     bool            Equal(const IAOrderedStorable* neighbor) const;
  29.  
  30.     // non-virtual implementations for use by performance-critical code
  31.     // note: this means that LessThan & Equal mustn't be overridden by subclasses
  32.     bool            LessThanNonVirtual(const IAOrderedStorable* neighbor) const;
  33.     bool            EqualNonVirtual(const IAOrderedStorable* neighbor) const;
  34.     
  35.     byte*            GetData() const {return data;}
  36.     const uint32    GetDataLength() const {return dataLen;}
  37. private:
  38.                     IATerm(byte* d, uint32 l, bool makeCopy);    
  39.     byte*            AllocData(uint32 l) const;    
  40.                     IATerm(IATerm&);                        // don't define a copy constructor
  41.     byte*            data;                                    // alloated with IAMallocArraySized
  42.     const uint32    dataLen;
  43.  
  44. };
  45.  
  46. class IAToken : public IAObject {
  47. public:
  48.                             IAToken(IATerm* t, uint32 s, uint32 e)
  49.                                     : term(t), startPos(s), endPos(e) {}
  50.     IA_INLINE          ~IAToken() IA_INLINE_DEF_BODY(delete term)
  51.  
  52.     IATerm*                GetTerm() const {return term;}
  53.     const uint32        GetStartPosition() const {return startPos;}
  54.     const uint32        GetEndPosition() const {return endPos;}
  55.  
  56. private:
  57.                             IAToken(IAToken&);                // don't define a copy constructor
  58.     // the unique type
  59.     IATerm*                    term;
  60.     // the byte position of the first character in the text corresponding to this token
  61.     const uint32            startPos;
  62.     // one greater than the position of the last character corresponding to this token
  63.     const uint32            endPos;
  64.  
  65. };
  66.  
  67. class IATokenStream : public IAObject {
  68. public:
  69.     IATokenStream() {};
  70.     virtual      ~IATokenStream() {};// no-op dtor def
  71.     // Returns the next token in the stream, or NULL at end of stream.
  72.     virtual IAToken*        GetNextToken() = 0;
  73.     // Copies into dest a span of bytes from the source text .
  74.     // The span must start less than a buffer before the end of the last token read, and
  75.     // it may not extend past the end of the last token read.
  76.     // If it starts more than a buffer before, AnalysisSpanUnavailable is signalled.
  77.     virtual void            GetTextSpan(byte* dest, uint32 startPos, uint32 endPos) = 0;
  78. };
  79.  
  80. IAExceptionCode                    AnalysisSpanUnavailable = 'VASU';
  81.  
  82. class IATokenFilter : public IATokenStream {
  83. public:
  84.                             IATokenFilter(IATokenStream* s);    // source = s;    
  85.                             ~IATokenFilter();                    // delete source;
  86.     // GetText() on a filter delegates to its source by default.                
  87.     void                    GetTextSpan(byte* buffer, uint32 startPos, uint32 endPos) {
  88.                                 source->GetTextSpan(buffer, startPos, endPos);
  89.                             }
  90. protected:
  91.  
  92.         IATokenStream* GetTokenStream() const {return source;}
  93. private:
  94.                             IATokenFilter(IATokenFilter& o); // don't define a copy constructor
  95.     // The source of tokens to be filtered.
  96.         IATokenStream*            source;
  97.  
  98. };
  99.  
  100. class IAAnalysis : public IAObject {
  101. public:
  102.                             IAAnalysis(uint32 type);         // : analysisType(type) {}
  103.     IA_INLINE                ~IAAnalysis() IA_INLINE_DEF()// no-op dtor def
  104.  
  105.     
  106.  
  107.     // Initializes persistent state, writing analysis paramters to storage.
  108.     virtual void            Initialize(IAStorage* storage, IABlockID block); // {}
  109.     // Reads persistent state, checking that it’s consistent with current parameters.
  110.     virtual void            Open(IAStorage* storage, IABlockID block);         // {}
  111.  
  112.     // Builds and returns a tokenizer.
  113.     virtual IATokenStream*    MakeTokenStream(IADocText* docText) = 0;
  114.     // returns a prototype term, for bootstrapping sets of terms
  115.     virtual IATerm*            GetProtoTerm() = 0;
  116.     
  117.     const uint32 GetAnalysisType() const {return analysisType;}
  118.     
  119. private:
  120.     const uint32            analysisType;
  121. };
  122.  
  123. #pragma IA_END_EXPORTS
  124.  
  125. #if PRAGMA_STRUCT_ALIGN
  126.     #pragma options align=reset
  127. #endif
  128.  
  129. #pragma import reset
  130.  
  131. #endif